package com.industrial.im.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.im.domain.DispatchEventTypeManagement;
import com.industrial.im.service.IDispatchEventTypeManagementService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 事项类型管理Controller
 *
 * @author SangGuangCan
 * @date 2024-03-08
 */
@RestController
@RequestMapping("/dispatch")
public class DispatchEventTypeManagementController extends BaseController
{
    @Autowired
    private IDispatchEventTypeManagementService dispatchEventTypeManagementService;

    /**
     * 查询事项类型管理列表
     */
    @RequiresPermissions("dispatch:dispatch:list")
    @GetMapping("/list")
    public TableDataInfo list(DispatchEventTypeManagement dispatchEventTypeManagement)
    {
        startPage();
        List<DispatchEventTypeManagement> list = dispatchEventTypeManagementService.selectDispatchEventTypeManagementList(dispatchEventTypeManagement);
        return getDataTable(list);
    }

    /**
     * 导出事项类型管理列表
     */
    @RequiresPermissions("dispatch:dispatch:export")
    @Log(title = "事项类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DispatchEventTypeManagement dispatchEventTypeManagement)
    {
        List<DispatchEventTypeManagement> list = dispatchEventTypeManagementService.selectDispatchEventTypeManagementList(dispatchEventTypeManagement);
        ExcelUtil<DispatchEventTypeManagement> util = new ExcelUtil<DispatchEventTypeManagement>(DispatchEventTypeManagement.class);
        util.exportExcel(response, list, "事项类型管理数据");
    }

    /**
     * 获取事项类型管理详细信息
     */
    @RequiresPermissions("dispatch:dispatch:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(dispatchEventTypeManagementService.selectDispatchEventTypeManagementByBaseId(baseId));
    }

    /**
     * 新增事项类型管理
     */
    @RequiresPermissions("dispatch:dispatch:add")
    @Log(title = "事项类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchEventTypeManagement dispatchEventTypeManagement)
    {
        return toAjax(dispatchEventTypeManagementService.insertDispatchEventTypeManagement(dispatchEventTypeManagement));
    }

    /**
     * 修改事项类型管理
     */
    @RequiresPermissions("dispatch:dispatch:edit")
    @Log(title = "事项类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchEventTypeManagement dispatchEventTypeManagement)
    {
        return toAjax(dispatchEventTypeManagementService.updateDispatchEventTypeManagement(dispatchEventTypeManagement));
    }

    /**
     * 删除事项类型管理
     */
    @RequiresPermissions("dispatch:dispatch:remove")
    @Log(title = "事项类型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(dispatchEventTypeManagementService.deleteDispatchEventTypeManagementByBaseIds(baseIds));
    }

    /**
     * <p>
     *     查询事项列表
     * </p>
     * @return
     */
    @GetMapping("/queryEventType")
    public AjaxResult queryEventType(){
        List<DispatchEventTypeManagement> list = dispatchEventTypeManagementService.queryEventType();
        return AjaxResult.success(list);
    }
}
